
local qingzhi = fk.CreateSkill {
  name = "lvshi__qingzhi",
  tags = {Skill.Lord, Skill.Compulsory}
}

Fk:loadTranslationTable{
  ["lvshi__qingzhi"] = "倾志",
  [":lvshi__qingzhi"] = "主公技，锁定技，蜀或汉势力角色于一回合首次获得你的手牌后，你摸一张牌；你因“聚烈”使用【杀】无距离限制，且次数和目标个数上限增加死亡的蜀或汉势力角色数。",
}

qingzhi:addEffect(fk.AfterCardsMove, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(qingzhi.name) then
      for _, move in ipairs(data) do
        if move.moveReason == fk.ReasonGive or move.moveReason == fk.ReasonPrey then
          if move.from and move.from == player and move.to and not table.contains(player:getTableMark("qingzhi-turn"), move.to.id)
          and (move.to.kingdom == "shu" or move.to.kingdom == "han") then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                return true
              end
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local mark = player:getTableMark("qingzhi-turn")
    for _, move in ipairs(data) do
      if move.moveReason == fk.ReasonGive or move.moveReason == fk.ReasonPrey then
        if move.from and move.from == player and move.to and (move.to.kingdom == "shu" or move.to.kingdom == "han") then
          table.insertIfNeed(mark, move.to.id)
        end
      end
    end
    player.room:setPlayerMark(player, "qingzhi-turn", mark)
    player:drawCards(1, qingzhi.name)
  end,
})

qingzhi:addEffect("targetmod", {
  bypass_distances =  function(self, player, skill, card, to)
    return skill.trueName == "slash_skill" and card.skillName == "lvshi__julie"
  end,
  residue_func = function(self, player, skill, scope, card)
    if skill.trueName == "slash_skill" and card.skillName == "lvshi__julie" then
      local n = #table.filter(Fk:currentRoom().players, function (p)
        return (p.kingdom == "shu" or p.kingdom == "han") and p.dead end)
      return n
    end
  end,
  extra_target_func = function(self, player, skill, card)
    if skill.trueName == "slash_skill" and card.skillName == "lvshi__julie" then
      local n = #table.filter(Fk:currentRoom().players, function (p)
        return (p.kingdom == "shu" or p.kingdom == "han") and p.dead end)
      return n
    end
  end,
})

return qingzhi